<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Amitav Roy
 * Date: 6/9/13
 * Time: 8:34 AM
 * To change this template use File | Settings | File Templates.
 */

class Transaction extends CI_Controller {
  public function __construct() {
    parent::__construct();
    auth_user();
    $this->carabiner->css('gmail-style.css');
    $this->carabiner->css('readable.min.css');
    $this->carabiner->js('libs/angular-ui-date.js');
    $this->carabiner->js('angularapp/angular_module.js');
    $this->carabiner->js('angularapp/transaction_app.js');
  }

  public function index() {
    $this->load->view('angular/page-html');
  }

  /*angular template urls*/
  public function view_trans() {
    $this->load->view('angular/templates/angular_transaction_view');
  }

  public function add_trans() {
    $this->load->view('angular/templates/angular_transaction_add');
  }

  /*angular ajax calls*/
  public function get_expenses($offset = null) {
    $this->load->model('expense_m', 'expense');
    if ($offset != null) {
      $limit = $this->expense->limit;
      $offsetRecords = $offset * $limit;
      $data = $this->expense->get_expense($offsetRecords);
    }
    else {
      $data = $this->expense->get_expense();
    }
    if ($data) {
      echo json_encode($data);
    }
    else {
      echo "No records found in expense table";
    }
  }
}